$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加折扣券发布', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field: 'z_num',
                title: '折扣数值',
                unresize: true,
                align: 'center',
                width:'10%'
            }, {
                field: 'i_num',
                title: '折扣券数量',
                unresize: true,
                align: 'center',
                width:'10%'
            }, {
                field: 'use_validate',
                title: '使用条件',
                unresize: true,
                align: 'center',
                width:'10%'
            }, {
                field: 'start_use',
                title: '开始日期',
                unresize: true,
                align: 'center',
                templet:function(d){
                    return d.start_use+' 至 '+ d.end_use;
                },
                width:'18%'
            }, {
                field: 'jump',
                title: '跳转类型',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.jump){
                        case 1: return '服务';break;
                        case 2: return '需求';break;
                        case 3: return '个人主页';break;
                    }
                },
                width:'10%'
            }, {
                title: '类型',
                unresize: true,
                align: 'center',
                 templet:function(d){
                    switch(d.type){
                        case 1: return '优惠券';break;
                        case 2: return '折扣券';break;
                        case 3: return '代金券';break;
                    }
                },
                width:'10%'
            }, {
                field: 'issue_time',
                title: '发布时间',
                unresize: true,
                align: 'center',
                width:'12%'
            }, {
                title: '状态',
                unresize: true,
                align: 'center',
                 templet:function(d){
                    switch(d.status){
                        case 0:  return '<span style="color:#B60000">已过期</span>';break;
                        case 1: return '<span style="color:#6590DC">正常</span>';break;
                    }
                },
                width:'10%'
            }, {
                field: 'user_id',
                title: '发布人编号',
                unresize: true,
                align: 'center',
                 templet:function(d){
                 return '<div style="cursor:pointer;text-decoration:underline;color:#6590DC" lay-event="user" >'+d.number+'</div>';
                },
                width:'10%'

            }, {
                title: '操作',
                unresize: true,
                align: 'center',
                toolbar: '#toolbar_normal',
                width:'10%'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'get') {
            layer_iframe('领取记录', '/before/coupon_get/index?foreign_key=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该折扣券发布吗?', 'before_coupon', obj.data.id);
        }else if (obj.event === 'user') {
            layer_iframe('会员信息', '/before/user/index?id=' + obj.data.user_id);

        }
    });
});
